Tiny Hexer Script: Variables
In Tiny Hexer script you can use variables to store specific
data.
Overview
Valid variable names are sequences of at least one alphanumeric
character or the underline character (_). A variable name must not start
with a number digit. Valid variable names are e.g. _1, Var1, _test_.
Invalid variable names are e.g. 1var, v$a. Identifiers reserved in Tiny
Hexer Script (like function and command names) cannot be used as variable
names.
Variables must be declared before accessing them in a script using the
VAR command. When a variable is
declared using the VAR command, its
data type is defined and cannot be changed
afterwards.
To assign data to a variable, use the LET command.
By default, sub routines (CALL and
LOOP commands) use copies of declared
variables (like environmental variables in batch scripts), so the sub
routine can access the variable and change its value locally, but after
termination of the sub routine (RETURN command) the original value of the
variable is restored. This behaviour can be changed using the OPTION GLOBALVARS directive.
Variable tagging
Variable tagging is used to create hyperlinks in the structure viewer. Each variable can have a
position and length tag. Variable tagging is disabled by default, this
behaviour can be controlled by the OPTION READTAGS directive.
If tagging is enabled, the FILEREAD command and function set the tag of the variable to the
file position before reading and the amount of data being read. The
following commands and functions allow you to access and modify variable
tags: COPYTAGS, TAGVAR, TAG_POS() and TAG_LEN().
Special variables
The following special variables exist in Tiny Hexer:
- ARGC (LONGWORD, readonly)
Reading this variable returns the number of parameters passed by the CALL
command and CALL() function.
See also CALL() function and CALL command.
-
COMPARE_COUNT*
(LONGWORD, readonly)
Reading this variable returns the number of difference blocks after a
file comparison has been
made.
See also COMPARE_START() and
COMPARE_END().
-
CURRENTFILE* (TEXT, read/write):
Reading this variable returns the filename of the active editor window.
If no editor window is open, the variable contains an empty text. On
setting this variable, Tiny Hexer tries to find an editor window whose
filename matches the value and brings it to front. If no matching editor
window is found, an error occurs.
-
ERRORLINE (LONGWORD, readonly):
Reading this variable returns the number of the script line where the
last error occurred.
See also ERRORHANDLER,
ERRORMESSAGE, ERRORNUMBER.
-
ERRORMESSAGE (TEXT, readonly):
Reading this variable returns the textual representation of the last
script error.
See also ERRORHANDLER,
ERRORLINE, ERRORNUMBER.
-
ERRORNUMBER (LONGWORD, readonly):
Reading this variable returns the numerical value of the last script
error. Some predefined errors exist, they are explained in the file
scripts\inc\def.mps
See also ERRORHANDLER,
ERRORLINE, ERRORMESSAGE.
-
FILE_COUNT* (LONGWORD, readonly):
Reading this variable returns the number of open editor files in Tiny
Hexer.
See also FILES().
- FRANDOM
(EXTENDED, read/write):
Reading this variable returns a floating point random number in the range
0..1.
Setting this variable changes the random seed value.
See also QRANDOM, RANDOM().
-
GETTEMPFILENAME*
(TEXT, readonly):
Reading this variable returns a unique filename in Tiny Hexer's temporary directory.
-
LANGUAGE_EXT* (TEXT, readonly):
this variable is mainly used in Tiny Hexer plugins. it tells the exe and
plugin language extension currently being used (empty string if Tiny
Hexer's language is English, '.DEU' if language is German).
See also localizing
scripts
- LOOP (LONGWORD, readonly):
On subroutine execution via the LOOP
command, this variable contains the current loop index.
-
NUMBER_PREFIX (TEXT, read/write):
Tells Tiny Hexer how it should convert numeric values to text using the
TEXT() function (e.g. '0x': 48 ->
'0x30', '$': 32 -> '$20').
-
NUMBER_RADIX (BYTE, read/write):
Tells Tiny Hexer how it should convert numeric values to text using the
TEXT() function (e.g. if set to 10,
numbers are converted to decimal text, if set to 16, numbers are
converted to hexadecimals and so on).
-
NUMBER_SUFFIX (TEXT, read/write):
Tells Tiny Hexer how it should convert numeric values to text using the
TEXT() function (e.g. 'h': 80 ->
'50h').
-
PARAM_COUNT (LONGWORD, readonly):
Stores the number of arguments passed to the script when it's started by
a tools menu item.
See also PARAMS().
- PI (EXTENDED, readonly):
This variable returns the value of the mathematical constant
PI.
-
POSITION_COUNT*
(LONGWORD, readonly):
Reading this variable returns the number of entries in the position list.
See also POSITIONS(), POSITION_ADD, POSITION_SELECTED(), POSITION_DESC.
-
POSITION_DESC*
(TEXT):
Sets or retrieves the text of the description in the position list.
See also POSITIONS(), POSITION_ADD, POSITION_SELECTED(), POSITION_COUNT.
- QRANDOM
(SIGQWORD, readonly):
Returns a 64 Bits wide random number.
See also FRANDOM, RANDOM().
-
SCRIPTFILENAME (TEXT, readonly):
Contains the file name of the script itself.
-
SCRIPTLINE (LONGWORD, readonly):
Contains the current script line number.
-
SCRIPTPOS (LONGWORD, readonly):
Contains the binary script position.
-
TYPEOFSTACK (LONGWORD, readonly):
Retrieves the type of the data on top of the
stack (the value retrieved by the POP command). Warning:
Do not use this variable in complex expressions as they store temporary
values on the stack themselves, rather assign this variable to a user
variable before working with it's value.
See also POP, TYPEOF().
|
|